var mongoose = require('mongoose'),
	Schema = mongoose.Schema,
    properties = require('../conf/properties'),
    baseDao = require('./baseDao');

var idSchema = new Schema(
	{
	    key : { type: String, unique: true, required: true },
	    nextId : { type: Number, required: true },
	}
);

//Conecto con la DB y seteo el Model
mongoose.connect(properties.mongodbConnectionURI);
var ids = mongoose.model('ids', idSchema);

module.exports.getAll = function (short, callback) {
	baseDao.getAll(ids, short, '["key", "nextId"]', callback);
}

module.exports.find = function (filters, callback) {
	baseDao.find(ids, filters, false, callback);
}

module.exports.findOne = function (filters, callback) {
	baseDao.find(ids, filters, true, callback);
}

module.exports.set = function (id, callback) {
	baseDao.set(ids, id, callback);
}

module.exports.update = function (key, data, callback) {
	baseDao.update(ids, 'key', key, data, callback);
}

module.exports.upsert = function (key, data, callback) {
	baseDao.upsert(ids, 'key', key, data, callback);
}

module.exports.remove = function (key, callback) {
	baseDao.remove(ids, 'key', key, callback);
}